<template>
  <div class="detail">
    <div class="header">
      <img src="../../../../assets/icons/back.png" alt="" @click="goBack">
    </div>
    <div class="content">
      <div class="danhao">
<!--        <p>单号编号: <span>{{$route.query.eventcode}}</span></p>-->
<!--        <p>情况说明: <span>{{eventDetail.evnettxt}}</span></p>-->
      </div>
<!--      <div class="step">-->
<!--        <van-steps :active="active" active-icon="success" active-color="#3178fd">-->
<!--          <van-step>-->
<!--            <p class="text" style="margin-bottom: 30px;margin-right:20px">上报事件</p>-->
<!--            <p>{{eventDetail.evnetWorkflow.up | dateformat1}}</p>-->
<!--          </van-step>-->
<!--          <van-step>-->
<!--            <p style="margin-bottom: 30px">处理中</p>-->
<!--            <p style="">{{eventDetail.evnetWorkflow.current | dateformat1}}</p>-->
<!--          </van-step>-->
<!--          <van-step>-->
<!--            <p style="margin-bottom: 30px">结束</p>-->
<!--            <p>{{eventDetail.evnetWorkflow.down | dateformat1}}</p>-->
<!--          </van-step>-->
<!--        </van-steps>-->
<!--      </div>-->
      <!--      反馈情况说明-->
      <div class="info" v-show="isShow">
        <p class="title">反馈情况说明 :</p>
        <ul class="body">
          <li v-for="(item, index) in infoArr" :key="index">
            {{item}}
          </li>
        </ul>
      </div>
      <!--      意见反馈-->
      <div class="feedback">
        <h2>意见反馈</h2>
        <span class="sep" v-show="showTip">*</span>
        <form action="">
          <label for="txt"/>
          <textarea
            @input="txtBlur"
            autofocus
            required
            name="txt"
            ref="txt"
            id="txt"
            cols="30" rows="10" maxlength="300" minlength="5"/>
        </form>
        <span class="desc" v-show="showTip">请描述遇到问题,以便我们能及时解决</span>
        <span class="num">输入5-300个字</span>
        <input type="submit" @click="submitForm">
      </div>
    </div>
  </div>
</template>

<script>
import { getEventDetail, feedBack } from '../../../../api'

export default {
  name: 'Detail',
  data () {
    return {
      active: '1',
      // 事件处理页面传过来的id
      eventcode: '',
      // 查询到的事情详情
      eventDetail: {},
      isShow: false, // 反馈提交之后的信息是否显示
      infoArr: [], // 定义一个存放反馈信息的数组
      showTip: true
    }
  },
  mounted () {
    this.eventcode = this.$route.query.eventcode
    console.log(this.eventcode)
    // 根据ID查看具体事件详情
    this.getEventDetailData()
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    },
    // 根据事件ID查看事件详情
    async getEventDetailData () {
      console.log(this.eventcode)
      const result = await getEventDetail(this.eventcode)
      console.log(result)
      this.eventDetail = result.data
      console.log(this.eventDetail)
    },
    // 提交文本域
    txtBlur () {
      this.showTip = false
    },
    async submitForm () {
      // 点击提交按钮提交反馈意见信息
      // console.log(1)
      // console.log(this.$refs.txt.value.length)
      // 首先尽心非空验证
      if (this.$refs.txt.value.trim().length === 0) {
        this.$toast('请填写反馈信息')
      } else {
        const result = await feedBack()
        console.log(result)
        if (result.code === '000000') {
          this.$toast('反馈成功')
          this.isShow = true
          this.infoArr.push(this.$refs.txt.value)
          this.$refs.txt.value = ''
          this.showTip = true
          // 点击提交之后显示情况说明文字
        }
      }
    }
  }
}
</script>

<style scoped lang="less">
  .detail {
    .header {
      padding: 10px 15px;
      border-bottom: 1px solid #e5e5e5;
      margin-bottom: 16px;

      img {
        width: 22px;
        height: 22px;
      }
    }

    .content {
      padding: 0 13px;

      .danhao {
        margin-bottom: 20px;

        p {
          color: #989898;
          font-size: 15px;
          margin-bottom: 15px;
          margin-top: 15px;

          &:nth-child(2) {
            line-height: 30px;
          }

          img {
            float: right;
            width: 20px;
            height: 20px;
            transform: rotate(270deg);
          }

          span {
            color: #4d4d4d;
            margin-left: 9px;
          }
        }
      }

      /*意见反馈信息*/

      .info {
        .title {
        }

        .body {
          margin-top: 10px;

          ul {
            li {
              margin-top: 15px;
              text-indent: 2rem;
            }
          }
        }
      }

      .feedback {
        position: relative;
        margin-top: 30px;
        /*必填项*/

        .sep {
          position: absolute;
          top: 54px;
          left: 10px;
          color: red;
          font-size: 14px;
        }

        h2 {
          font-size: 13px;
          color: #4d4d4d;
          margin-bottom: 19px;
        }

        textarea {
          cursor: pointer;
          height: 100%;
          width: 100%;
          border: 1px solid #cecbcc;
          background-color: #f4f4f4;
          font-size: 12px;

          &::-webkit-input-placeholder { /* WebKit browsers 适配谷歌 */
            color: #b7b1b3;
          }

          &::-moz-placeholder { /* Mozilla Firefox 4 to 18 适配火狐 */
            color: #b7b1b3;
          }

          &::-moz-placeholder { /* Mozilla Firefox 19+ 适配火狐 */
            color: #b7b1b3;
          }

          &::-ms-input-placeholder { /* Internet Explorer 10+  适配ie*/
            color: #b7b1b3;
          }
        }

        .desc {
          position: absolute;
          top: 50px;
          left: 17px;
          color: #b7b1b3;
        }

        .num {
          position: absolute;
          right: 16px;
          bottom: 80px;
          color: #b7b1b3;
          font-size: 12px;
        }

        input[type='submit'] {
          height: 46px;
          width: 100%;
          background-color: #1989fa;
          border-radius: 18px;
          margin-top: 20px;
          color: #fff;
        }
      }

    }
  }
</style>
